package ru.lukyanets.transmission.protocol.client;

import ru.lukyanets.transmission.protocol.model.session.Session;
import ru.lukyanets.transmission.protocol.model.session.stats.SessionStats;
import ru.lukyanets.transmission.protocol.model.torrent.Torrent;
import ru.lukyanets.transmission.protocol.model.torrent.arguments.TorrentSetArgs;
import ru.lukyanets.transmission.protocol.client.exception.TransmissionException;

import java.util.List;

/**
 * @author slukyanets
 */
public interface RpcClient {

    /**
     * Getting torrents list on the server.
     *
     * @return list of torrents added to the server.
     */
    List<Torrent> getTorrents() throws TransmissionException;

    /**
     * Getting torrent by ID.
     *
     * @param id - torrent ID on the server
     * @return torrent added to the server.
     */
    Torrent getTorrent(int id) throws TransmissionException;

    /**
     * Setting torrent parameters.
     *
     * @param arguments - torrent set arguments
     */
    void setTorrent(TorrentSetArgs arguments) throws TransmissionException;

    /**
     * Make action on torrent.
     *
     * @param ids    - list of torrent identifiers
     * @param action - the action to be made
     */
    void actionTorrent(List<Integer> ids, TorrentAction action) throws TransmissionException;

    /**
     * Add torrent on server.
     *
     * @param metainfo          - base64 encoded .torrent file content
     * @param files             - torrent FILES list
     * @param cookies           - The format of the "cookies" should be NAME=CONTENTS, where NAME is the
     *                          cookie NAME and CONTENTS is what the cookie should contain.
     *                          Set multiple cookies like this: "name1=content1; name2=content2;" etc.
     *                          <http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCOOKIE>
     * @param downloadDir       - path to download the torrent to
     * @param paused            - if true, don't start the torrent
     * @param peerLimit         - maximum number of PEERS
     * @param bandwidthPriority - torrent's bandwidth
     * @return - torrent identifier
     */
    int addTorrent(String metainfo, List<TorrentFileMarker> files, String cookies,
                          String downloadDir, boolean paused, int peerLimit, int bandwidthPriority) throws TransmissionException;

    /**
     * Remove torrent from server.
     *
     * @param ids             - list of torrent identifiers
     * @param deleteLocalData - delete local data.
     */
    void removeTorrent(List<Integer> ids, boolean deleteLocalData) throws TransmissionException;

    /**
     * Set new Location for torrent data.
     *
     * @param ids      - list of torrent identifiers
     * @param location - the new torrent location
     * @param move     - if true, move from previous location, otherwise, search "location" for FILES
     */
    void setLocationTorrent(List<Integer> ids, String location, boolean move) throws TransmissionException;

    /**
     * Rename torrent path.
     *
     * @param ids  - list of torrent identifiers
     * @param path - the path to the file or folder that will be renamed
     * @param name - the file or folder's new NAME
     */
    void renamePathTorrent(List<Integer> ids, String path, String name) throws TransmissionException;

    /**
     * Rename torrent path.
     *
     * @param ids    - list of torrent identifiers
     * @param action - action to be made
     */
    void actionQueue(List<Integer> ids, QueueAction action) throws TransmissionException;

    /**
     * This method tests to see if your incoming peer port is accessible
     * from the outside world.
     *
     * @return true if port is open
     */
    boolean testPort() throws TransmissionException;

    /**
     * Getting transmission server session information.
     *
     * @return session information object.
     */
    Session getSession() throws TransmissionException;

    /**
     * Update session parameters.
     *
     * @param session - session data to update
     */
    void setSession(Session session) throws TransmissionException;

    /**
     * This method tells the transmission session to shut down.
     */
    void shutdownServer() throws TransmissionException;

    /**
     * Getting transmission server session statistic.
     *
     * @return session statistic object.
     */
    SessionStats getSessionStats() throws TransmissionException;

    void updateBlocklist() throws TransmissionException;
}
